<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            margin: 0;
        }
        .top{
            width: 100%;
            height: 100px;
            background-color: khaki;
        }
        .nav{
            height: 80px;
            width: 100%;
            background-color: skyblue;
        }
        .main{
            height: 1500px;
            background-image: linear-gradient(to bottom,red, skyblue);
        }

        .sticky{
            position: sticky;
            /* 与body的距离 */
            top:0px; 
        }
    </style>
</head>
<body>
    <!-- 粘性定位元素作为body的直接元素 -->
     <div class="top"></div>
     <div class="nav sticky"></div>
     <div class="main"></div>
</body>
</html>